//
//  MHChangeDateViewController.m
//  ManHua
//
//  Created by 江子安 on 15/11/2.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHChangeDateViewController.h"

@interface MHChangeDateViewController ()

@property (nonatomic, strong) UITextField *dateTF;
@property (nonatomic, strong) UIDatePicker *picker;
@end

@implementation MHChangeDateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"出生日期";
    
    self.dateTF = [[UITextField alloc]initWithFrame:CGRectMake(10, 94, Width - 20, 44)];
    _dateTF.backgroundColor = [UIColor whiteColor];
    _dateTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    _dateTF.textAlignment = NSTextAlignmentRight;
    _dateTF.rightView = [[UIView alloc]initWithFrame:CGRectMake(Width - 40, 0, 20, 44)];
    _dateTF.text = _birthday;
    _dateTF.rightViewMode = UITextFieldViewModeAlways;
    UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, 80, 44)];
    dateLabel.text = @"日期";
    _dateTF.leftView = dateLabel;
    _dateTF.leftViewMode = UITextFieldViewModeAlways;
    _dateTF.borderStyle = UITextBorderStyleRoundedRect;
    [self.view addSubview:_dateTF];
    
    _picker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, Height - 200, Width, 200)];
    _picker.backgroundColor = [UIColor whiteColor];
    _picker.datePickerMode = UIDatePickerModeDate;
    [_picker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:_picker];
    
}

- (void)dateChanged:(UIDatePicker *)sender
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date = sender.date;
    _dateTF.text = [formatter stringFromDate:date];
    _birthday = _dateTF.text;
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
